<?php
class DBConfig {
    /**
     * static db config
     * @var mixed array
     */
	protected static $_config = array();
	/**
	 * set db config
	 * @param $db string
	 * @param $user string
	 * @param $passwd string
	 * @param $port int
	 * @param $host string
	 * @param $isMaster bool
	 */
	public static function set($dbName, $user, $passwd, $port, $host, 
	                       $isMaster = false) {
	    $key = SLAVE;
	    if (!empty($isMaster)) {
	        $key = MASTER;
	    }
	    self::$_config[$dbName][$key] = array(
	            USER => $user,
	            PASSWD => $passwd,
	            PORT => $port,
	            HOST => $host
	    ); 
	}
	/**
	 * get db config
	 * @param string $dbName
	 * @param string $model
	 * @return array
	 */
    public static function get($dbName, $model=SLAVE) {
		$ret = array();
		if( empty(self::$_config[$dbName]) ) {
			return $ret;
		} 
		if( empty(self::$_config[$dbName][$model]) ) {
			return $ret;
		}
		$ret = self::$_config[$dbName][$model];
		empty($ret[DBNAME]) && $ret[DBNAME] = $dbName;
		
		return $ret;
	}
}
/**
 * DBConfig::set('test', 'test', 'passwd', '3306', 'server.test.db');       //slave
 * DBConfig::set('test', 'test', 'passwd', '3306', 'server.test.db', true); //master
 */
DBConfig::set('test', 'test', 'test', '3306', 'localhost');       //slave
DBConfig::set('test', 'test', 'test', '3306', 'localhost', true); //master